﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Isha.Entities;
using System.Text.RegularExpressions;

namespace Isha.Infrastructure
{
    public static class ContentItemExtensions
    {
        public static ContentItem UrlFix(this ContentItem contentItem)
        {
            string urlbug = @"\s|$|&|\.|:|<|>|[|]|\+|#|%|\@|\""|/|;|=|\?|\\|\^|~|'|,";
            //TODO: To work on this
            if (string.IsNullOrEmpty(contentItem.Link))
                contentItem.Link = Regex.Replace(contentItem.Title, urlbug, "-",
                RegexOptions.Compiled | RegexOptions.IgnoreCase).ToLower().TrimEnd('-');
            else
                contentItem.Link = Regex.Replace(contentItem.Link, urlbug, "-",
                RegexOptions.Compiled | RegexOptions.IgnoreCase).ToLower().TrimEnd('-');

            return contentItem;
        }
    }
}
